<template>
    <div class="index-lists">

        <el-card class="!border-none mt-4" shadow="never">
            <div>
                <el-button v-perms="['remind:add']" type="primary" @click="handleAdd()">
                    <template #icon>
                        <icon name="el-icon-Plus" />
                    </template>
                    新增
                </el-button>
            </div>
            <el-table class="mt-4" size="large" v-loading="pager.loading" :data="pager.lists" stripe>
                <el-table-column label="请款单号" prop="paymentRequestNumber" min-width="120" />
                <el-table-column label="发票号" prop="invoiceNumber" min-width="120" />
                <el-table-column label="创建人" prop="creator" min-width="120" />
                <el-table-column label="币别" prop="currency" min-width="120" />
                <el-table-column label="代理折扣费" prop="agencyDiscountFee" min-width="120" />
                <el-table-column label="请款金额" prop="claimAmount" min-width="120" />
                <el-table-column label="官费" prop="officialFee" min-width="120" />
                <el-table-column label="代理费" prop="agencyFee" min-width="120" />
                <el-table-column label="原始币别" prop="originalCurrency" min-width="120" />
                <el-table-column label="原始请款总额" prop="totalOriginalRequest" min-width="120" />
                <el-table-column label="原始官费" prop="originalOfficialFee" min-width="120" />
                <el-table-column label="原始代理费" prop="originalCommissionFee" min-width="120" />
                <el-table-column label="到款金额" prop="amountReceived" min-width="120" />
                <el-table-column label="到账日期" prop="receivedDate" min-width="120" />
                <el-table-column label="最后办理时间" prop="finalProcessingTime" min-width="120" />
            </el-table>
            <div class="flex justify-end mt-4">
                <pagination v-model="pager" @change="getLists" />
            </div>
        </el-card>
        <edit-popup v-if="showEdit" ref="editRef" @success="getLists" @close="showEdit = false" />
      <footer-btns>
        <div style="padding: 20px">
          <el-button v-perms="['basic:add']" type="primary" @click="handleSubmit">
            <template #icon>
              <icon name="el-icon-Plus" />
            </template>
            新增
          </el-button>
          <el-button
              v-perms="['customerlist:add/edit']"
              type="primary"
              @click="save()"
          >
            <template #icon>
              <icon name="el-icon-FolderChecked" />
            </template>
            保存
          </el-button>
          <el-button @click="resetParams">重置</el-button>
        </div>
      </footer-btns>
    </div>
</template>
<script lang="ts" setup name="withdrawContract">
import { withdrawContractDelete, withdrawContractLists } from '@/api/withdrawContract'
import { usePaging } from '@/hooks/usePaging'
import feedback from '@/utils/feedback'
import EditPopup from './withdrawEdit.vue'
const editRef = shallowRef<InstanceType<typeof EditPopup>>()
const showEdit = ref(false)
const queryParams = reactive({
    paymentRequestNumber: '',
    invoiceNumber: '',
    creator: '',
    currency: '',
    currencyid: '',
    agencyDiscountFee: '',
    claimAmount: '',
    officialFee: '',
    agencyFee: '',
    originalCurrency: '',
    totalOriginalRequest: '',
    originalOfficialFee: '',
    originalCommissionFee: '',
    amountReceived: '',
    receivedDate: '',
    finalProcessingTime: ''
})

const { pager, getLists, resetPage, resetParams } = usePaging({
    fetchFun: withdrawContractLists,
    params: queryParams
})

const handleAdd = async () => {
    showEdit.value = true
    await nextTick()
    editRef.value?.open('add')
}

const handleEdit = async (data: any) => {
    showEdit.value = true
    await nextTick()
    editRef.value?.open('edit')
    editRef.value?.getDetail(data)
}

const handleDelete = async (id: number) => {
    await feedback.confirm('确定要删除？')
    await withdrawContractDelete({ id })
    feedback.msgSuccess('删除成功')
    getLists()
}

getLists()
</script>
